package com.icez.designmode

import android.graphics.Bitmap
import android.net.http.SslError
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.webkit.*
import android.widget.Button
import com.icez.bwebviewlibrary.BWebView
import com.icez.bwebviewlibrary.BWebView.Companion.ANDROID_ASSET_INDEX

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val bwv = findViewById<BWebView>(R.id.bwv)
        val btn = findViewById<Button>(R.id.btn)


        //设置js交互桥梁
        bwv.setJsBridge(WebJsBridge(),"aos")

        btn.setOnClickListener {
            //android调用js方法
            bwv.toJsMethod("androidToJs")
        }

        //生命周期绑定
        lifecycle.addObserver(bwv)


        //加载的远程地址
        var url = "https://static-download2.tripbay.com/prod/html/static/zh_CN/terms_of_service.html?t=1692762231554"

        //加载的本地地址
        var localUrl = "${BWebView.ANDROID_ASSET_INDEX}test.html"

        //加载网页
        bwv.loadWeb( localUrl, onProgressChangedListener = {
            Log.e("icez", "页面加载完毕")
        }, onPageErrorListenner = {errorResponse: WebResourceResponse?,error: WebResourceError?->

        })
    }
}